package com.soccertgc.comm
{
	import com.soccertgc.comm.CallEvent;
	import com.soccertgc.utils.ErrorUtils;

	public class CallFailEvent extends CallEvent
	{
		
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private var _message:String;
		private var _error:Error;
		private var _canRetry:Boolean;
		private var _failType:CallFailType;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTOR
		// -------------------------------------------------------------------------------
		
		public function CallFailEvent(call:Call, failType:CallFailType, message:String = null, error:Error = null, canRetry:Boolean = false)
		{
			super(CallEvent.EVENT_CALL_FAIL, call);
			_failType = failType;
			_message = message;
			_error = error;
			_canRetry = canRetry;
		}

		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------
		
		public function get failType():CallFailType
		{
			return _failType;
		}

		public function get error():Error
		{
			return _error;
		}

		public function get message():String
		{
			return _message;
		}
		
		public function get canRetry():Boolean
		{
			return _canRetry;
		}
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		override public function toString():String
		{
			return "Call " + _call.url + " failed: " + _message + " (type: " + _failType.name + ", error: " + ErrorUtils.toString(_error) + ") - url: " + _call.toUrl() + ")"; 
		}


	}
}